package com.baoxin.service.impl;

import com.baoxin.domain.User;
import com.baoxin.mapper.UserMapper;
import com.baoxin.service.UserService;
import com.baoxin.utils.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Rose
 * @Date: 2020/4/24 16:36
 * @version: 1.0.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;//会报红线

    @Override
    public Result findAll() {
        List<User> users = userMapper.findAll();
        return new Result("0","查询成功","查询成功",users);
    }

    @Override
    public Result selectByPrimaryKey(Integer id) {
        User user = userMapper.selectByPrimaryKey(id);
        return new Result("0","查询成功","查询成功",user);
    }

    @Override
    public Result insert(User user) {
        int result = userMapper.insert(user);
        if(result==1){
            return new Result("0","新增成功","新增成功",result);
        }
        return new Result("1","新增失败","新增失败",result);
    }

    @Override
    public Result findByPaging(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<User> userList = userMapper.findByPaging();
        return new Result("0","查询成功","查询成功",userList);
    }

}
